/*
 * Copyright (c) 2011 Ball State University
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package edu.bsu.android.gtv.apps.bconnected.parser;

import java.util.List;

import android.app.Activity;

import edu.bsu.android.gtv.apps.bconnected.parser.AndroidSaxServiceParser;
import edu.bsu.android.gtv.apps.bconnected.parser.ServiceParser;
import edu.bsu.android.gtv.apps.bconnected.util.LoginHelper;
import edu.bsu.android.gtv.apps.bconnected.util.Constants;

/**
 * Handles the calls to the various service parsers for the .NET application
 * @author Kyle Parker, University Computing Services
 */
public abstract class ParserFactory {
	// TODO: Add URLs to the service handlers for the data source
	static String url = "";
	static String demoUrl = "";
	
	static String advisorUrl = "academics/advisorlist.ashx?";
	static String classmateUrl = "courses/classmates.ashx?";
	static String contentUrl = "news/content.ashx?";
	static String degreeUrl = "academics/degreelist.ashx?";
	static String eventInfoUrl = "events/eventinfo.ashx?";
	static String eventUrl = "events/eventlist.ashx?";
	static String housingUrl = "housing/housinginfo.ashx?";
	static String instructorUrl = "courses/instructor.ashx?";
	static String logoutUrl = "auth/logout.ashx?";
	static String memberUrl = "organizations/members.ashx?";
	static String organizationInfoUrl = "organizations/organizationinfo.ashx?";
	static String organizationUrl = "organizations/organizationlist.ashx?";
	static String orgsCategoryUrl = "organizations/categorylist.ashx?";
	static String otherCoursesUrl = "courses/othercourses.ashx?";
	static String personUrl = "people/search.ashx?";
	static String roommateUrl = "housing/roommates.ashx?";
	static String scheduleUrl = "courses/schedule.ashx?";
	static String sharedCoursesUrl = "courses/sharedcourses.ashx?";
	static String termUrl = "terms/search.ashx?";

	/**
	 * Return a new {@link AndroidSaxServiceParser} based on the URL and the querystring parameters
	 * @param intServiceType
	 * @param querystringParms
	 * @return AndroidSaxServiceParser
	 */
	public static ServiceParser getParser(int intServiceType, List<String> querystringParms, Activity activity) {
		switch (intServiceType) {
			case Constants.SERVICE_TYPE_ADVISOR:
				if (LoginHelper.isDemoAccount(activity)) {
					return new AndroidSaxServiceParser(demoUrl + advisorUrl, querystringParms);
				} else {
					return new AndroidSaxServiceParser(url + advisorUrl, querystringParms);
				}
			case Constants.SERVICE_TYPE_CLASSMATE:
				if (LoginHelper.isDemoAccount(activity)) {
					return new AndroidSaxServiceParser(demoUrl + classmateUrl, querystringParms);
				} else {
					return new AndroidSaxServiceParser(url + classmateUrl, querystringParms);
				}
			case Constants.SERVICE_TYPE_CONTENT:
				return new AndroidSaxServiceParser(url + contentUrl, querystringParms);
			case Constants.SERVICE_TYPE_DEGREE:
				if (LoginHelper.isDemoAccount(activity)) {
					return new AndroidSaxServiceParser(demoUrl + degreeUrl, querystringParms);
				} else {
					return new AndroidSaxServiceParser(url + degreeUrl, querystringParms);
				}
			case Constants.SERVICE_TYPE_EVENT:
				return new AndroidSaxServiceParser(url + eventUrl, querystringParms);
			case Constants.SERVICE_TYPE_EVENT_INFO:
				return new AndroidSaxServiceParser(url + eventInfoUrl, querystringParms);
			case Constants.SERVICE_TYPE_HOUSING:
				if (LoginHelper.isDemoAccount(activity)) {
					return new AndroidSaxServiceParser(demoUrl + housingUrl, querystringParms);
				} else {
					return new AndroidSaxServiceParser(url + housingUrl, querystringParms);
				}
			case Constants.SERVICE_TYPE_INSTRUCTOR:
				if (LoginHelper.isDemoAccount(activity)) {
					return new AndroidSaxServiceParser(demoUrl + instructorUrl, querystringParms);
				} else {
					return new AndroidSaxServiceParser(url + instructorUrl, querystringParms);
				}
			case Constants.SERVICE_TYPE_LOGOUT:
				if (LoginHelper.isDemoAccount(activity)) {
					return new AndroidSaxServiceParser(demoUrl + logoutUrl, querystringParms);
				} else {
					return new AndroidSaxServiceParser(url + logoutUrl, querystringParms);
				}
			case Constants.SERVICE_TYPE_MEMBER:
				if (LoginHelper.isDemoAccount(activity)) {
					return new AndroidSaxServiceParser(demoUrl + memberUrl, querystringParms);
				} else {
					return new AndroidSaxServiceParser(url + memberUrl, querystringParms);
				}
			case Constants.SERVICE_TYPE_ORGANIZATION:
				if (LoginHelper.isDemoAccount(activity)) {
					return new AndroidSaxServiceParser(demoUrl + organizationUrl, querystringParms);
				} else {
					return new AndroidSaxServiceParser(url + organizationUrl, querystringParms);
				}
			case Constants.SERVICE_TYPE_ORGANIZATION_CATEGORY:
				return new AndroidSaxServiceParser(url + orgsCategoryUrl, querystringParms);
			case Constants.SERVICE_TYPE_ORGANIZATION_INFO:
				if (LoginHelper.isDemoAccount(activity)) {
					return new AndroidSaxServiceParser(demoUrl + organizationInfoUrl, querystringParms);
				} else {
					return new AndroidSaxServiceParser(url + organizationInfoUrl, querystringParms);
				}
			case Constants.SERVICE_TYPE_OTHER_COURSES:
				if (LoginHelper.isDemoAccount(activity)) {
					return new AndroidSaxServiceParser(demoUrl + otherCoursesUrl, querystringParms);
				} else {
					return new AndroidSaxServiceParser(url + otherCoursesUrl, querystringParms);
				}
			case Constants.SERVICE_TYPE_PERSON:
				if (LoginHelper.isDemoAccount(activity)) {
					return new AndroidSaxServiceParser(demoUrl + personUrl, querystringParms);
				} else {
					return new AndroidSaxServiceParser(url + personUrl, querystringParms);
				}
			case Constants.SERVICE_TYPE_ROOMMATE:
				if (LoginHelper.isDemoAccount(activity)) {
					return new AndroidSaxServiceParser(demoUrl + roommateUrl, querystringParms);
				} else {
					return new AndroidSaxServiceParser(url + roommateUrl, querystringParms);
				}
			case Constants.SERVICE_TYPE_SCHEDULE:
				if (LoginHelper.isDemoAccount(activity)) {
					return new AndroidSaxServiceParser(demoUrl + scheduleUrl, querystringParms);
				} else {
					return new AndroidSaxServiceParser(url + scheduleUrl, querystringParms);
				}
			case Constants.SERVICE_TYPE_SHARED_COURSE:
				if (LoginHelper.isDemoAccount(activity)) {
					return new AndroidSaxServiceParser(demoUrl + sharedCoursesUrl, querystringParms);
				} else {
					return new AndroidSaxServiceParser(url + sharedCoursesUrl, querystringParms);
				}
			case Constants.SERVICE_TYPE_TERM:
				if (LoginHelper.isDemoAccount(activity)) {
					return new AndroidSaxServiceParser(demoUrl + termUrl, querystringParms);
				} else {
					return new AndroidSaxServiceParser(url + termUrl, querystringParms);
				}
			default: 
				return null;
		}
	}
}